// src/stores/userStore.ts
import { defineStore } from 'pinia'

interface UserState {
  name: string
  isLoggedIn: boolean
}

export const useUserStore = defineStore('user', {
  state: (): UserState => ({
    name: '',
    isLoggedIn: false
  }),
  getters: {
    welcomeMessage: (state) =>
      state.isLoggedIn ? `欢迎回来，${state.name}` : '请先登录'
  },
  actions: {
    login(name: string) {
      this.name = name
      this.isLoggedIn = true
    },
    logout() {
      this.name = ''
      this.isLoggedIn = false
    }
  }
})
